from pulp import *

prob = LpProblem("Max Flow Problem",LpMaximize)

fs0 = LpVariable("s0",0,cat=LpInteger)
fs1 = LpVariable("s1",0,cat=LpInteger)
fs2 = LpVariable("s2",0,cat=LpInteger)
fs3 = LpVariable("s3",0,cat=LpInteger)
fs4 = LpVariable("s4",0,cat=LpInteger)
fs5 = LpVariable("s5",0,cat=LpInteger)

f06 = LpVariable("06",0,20,LpInteger)
f07 = LpVariable("07",0,10,LpInteger)

f17 = LpVariable("17",0,10,LpInteger)
f18 = LpVariable("18",0,10,LpInteger)

f23 = LpVariable("23",0,15,LpInteger)
f28 = LpVariable("28",0,40,LpInteger)
f29 = LpVariable("29",0,25,LpInteger)

f32 = LpVariable("32",0,15,LpInteger)
f39 = LpVariable("39",0,5,LpInteger)

f49 = LpVariable("49",0,10,LpInteger)
f410 = LpVariable("410",0,10,LpInteger)

f510 = LpVariable("510",0,10,LpInteger)

f60 = LpVariable("60",0,20,LpInteger)
f67 = LpVariable("67",0,10,LpInteger)
f618 = LpVariable("618",0,20,LpInteger)

f70 = LpVariable("70",0,10,LpInteger)
f71 = LpVariable("71",0,10,LpInteger)
f76 = LpVariable("76",0,10,LpInteger)
f78 = LpVariable("78",0,10,LpInteger)
f718 = LpVariable("718",0,10,LpInteger)

f81 = LpVariable("81",0,10,LpInteger)
f82 = LpVariable("82",0,40,LpInteger)
f87 = LpVariable("87",0,10,LpInteger)
f812 = LpVariable("812",0,10,LpInteger)

f92 = LpVariable("92",0,25,LpInteger)
f93 = LpVariable("93",0,5,LpInteger)
f94 = LpVariable("94",0,10,LpInteger)
f911 = LpVariable("911",0,15,LpInteger)
f912 = LpVariable("912",0,20,LpInteger)

f104 = LpVariable("104",0,10,LpInteger)
f105 = LpVariable("105",0,10,LpInteger)
f1011 = LpVariable("1011",0,20,LpInteger)

f119 = LpVariable("119",0,15,LpInteger)
f1110 = LpVariable("1110",0,20,LpInteger)
f1113 = LpVariable("1113",0,20,LpInteger)
f1114 = LpVariable("1114",0,20,LpInteger)

f128 = LpVariable("128",0,10,LpInteger)
f129 = LpVariable("129",0,20,LpInteger)
f1215 = LpVariable("1215",0,30,LpInteger)
f1217 = LpVariable("1217",0,30,LpInteger)
f1223 = LpVariable("1223",0,10,LpInteger)

f1311 = LpVariable("1311",0,20,LpInteger)
f1314 = LpVariable("1314",0,10,LpInteger)
f1315 = LpVariable("1315",0,40,LpInteger)

f1411 = LpVariable("1411",0,20,LpInteger)
f1413 = LpVariable("1413",0,10,LpInteger)
f1415 = LpVariable("1415",0,10,LpInteger)
f1419 = LpVariable("1419",0,30,LpInteger)

f1512 = LpVariable("1512",0,30,LpInteger)
f1513 = LpVariable("1513",0,40,LpInteger)
f1514 = LpVariable("1514",0,10,LpInteger)
f1516 = LpVariable("1516",0,10,LpInteger)
f1519 = LpVariable("1519",0,30,LpInteger)
f1524 = LpVariable("1524",0,10,LpInteger)

f1615 = LpVariable("1615",0,10,LpInteger)
f1619 = LpVariable("1619",0,50,LpInteger)
f1624 = LpVariable("1624",0,200,LpInteger)
f1625 = LpVariable("1625",0,200,LpInteger)

f1712 = LpVariable("1712",0,30,LpInteger)
f1718 = LpVariable("1718",0,30,LpInteger)
f1723 = LpVariable("1723",0,10,LpInteger)

f186 = LpVariable("186",0,20,LpInteger)
f187 = LpVariable("187",0,10,LpInteger)
f1817 = LpVariable("1817",0,30,LpInteger)
f1820 = LpVariable("1820",0,10,LpInteger)
f1821 = LpVariable("1821",0,10,LpInteger)

##f1914 = LpVariable("1914",0,30,LpInteger)
##f1915 = LpVariable("1915",0,30,LpInteger)
##f1916 = LpVariable("1916",0,50,LpInteger)

f2018 = LpVariable("2018",0,10,LpInteger)
f2022 = LpVariable("2022",0,50,LpInteger)
f2026 = LpVariable("2026",0,50,LpInteger)

f2118 = LpVariable("2118",0,10,LpInteger)
f2122 = LpVariable("2122",0,50,LpInteger)
f2123 = LpVariable("2123",0,50,LpInteger)

f2220 = LpVariable("2220",0,50,LpInteger)
f2221 = LpVariable("2221",0,50,LpInteger)
f2223 = LpVariable("2223",0,50,LpInteger)
f2224 = LpVariable("2224",0,50,LpInteger)
f2225 = LpVariable("2225",0,50,LpInteger)
f2226 = LpVariable("2226",0,50,LpInteger)

f2312 = LpVariable("2312",0,10,LpInteger)
f2317 = LpVariable("2317",0,10,LpInteger)
f2321 = LpVariable("2321",0,50,LpInteger)
f2322 = LpVariable("2322",0,50,LpInteger)
f2324 = LpVariable("2324",0,50,LpInteger)

f2415 = LpVariable("2415",0,10,LpInteger)
f2416 = LpVariable("2416",0,200,LpInteger)
f2422 = LpVariable("2422",0,50,LpInteger)
f2423 = LpVariable("2423",0,50,LpInteger)

f2516 = LpVariable("2516",0,200,LpInteger)
f2522 = LpVariable("2522",0,50,LpInteger)
f2526 = LpVariable("2526",0,50,LpInteger)

f2620 = LpVariable("2620",0,50,LpInteger)
f2622 = LpVariable("2622",0,50,LpInteger)
f2625 = LpVariable("2625",0,50,LpInteger)


prob += fs0 + fs1 + fs2 + fs3 + fs4 + fs5, "Maximum Flow"

prob += fs0 - f06 - f07 <= 0, "Node 0 flow conservation pos"
prob += -1*(fs0 - f06 - f07) <= 0, "Node 0 flow conservation neg"

prob += fs1 - f17 - f18 <= 0, "Node 1 flow conservation pos"
prob += -1*(fs1 - f17 - f18) <= 0, "Node 1 flow conservation neg"

prob += fs2 - f23 - f28 - f29 <= 0, "Node 2 flow conservation pos"
prob += -1*(fs2 - f23 - f28 - f29) <= 0, "Node 2 flow conservation neg"

prob += fs3 - f32 - f39 <= 0, "Node 3 flow conservation pos"
prob += -1*(fs3 - f32 - f39) <= 0, "Node 3 flow conservation neg"

prob += fs4 - f49 - f410 <= 0, "Node 4 flow conservation pos"
prob += -1*(fs4 - f49 - f410) <= 0, "Node 4 flow conservation neg"

prob += fs5 - f510 <= 0, "Node 5 flow conservation pos"
prob += -1*(fs5 - f510) <= 0, "Node 5 flow conservation neg"

prob += f06 + f76 + f186 - f60 - f67 - f618 <= 0, "Node 6 flow conservation pos"
prob += -1*(f06 + f76 + f186 - f60 - f67 - f618) <= 0, "Node 6 flow conservation neg"

prob += f07 + f17 + f67 + f87 + f187 - f70 - f71 - f76 - f78 - f718 <= 0, "Node 7 flow conservation pos"
prob += -1*(f07 + f17 + f67 + f87 + f187 - f70 - f71 - f76 - f78 - f718) <= 0, "Node 7 flow conservation neg"

prob += f18 + f28 + f78 + f128 - f81 - f82 - f87 - f812 <= 0, "Node 8 flow conservation pos"
prob += -1*(f18 + f28 + f78 + f128 - f81 - f82 - f87 - f812) <= 0, "Node 8 flow conservation neg"

prob += f29 + f39 + f49 + f119 + f129 - f92 - f93 - f94 - f911 - f912 <= 0, "Node 9 flow conservation pos"
prob += -1*(f29 + f39 + f49 + f119 + f129 - f92 - f93 - f94 - f911 - f912) <= 0, "Node 9 flow conservation neg"

prob += f410 + f510 + f1110 - f104 - f105 - f1011 <= 0, "Node 10 flow conservation pos"
prob += -1*(f410 + f510 + f1110 - f104 - f105 - f1011) <= 0, "Node 10 flow conservation neg"

prob += f911 + f1011 + f1311 + f1411 - f119 - f1110 - f1113 - f1114 <= 0, "Node 11 flow conservation pos"
prob += -1*(f911 + f1011 + f1311 + f1411 - f119 - f1110 - f1113 - f1114) <= 0, "Node 11 flow conservation neg"

prob += f812 + f912 + f1512 + f1712 + f2312 - f128 - f129 - f1215 - f1217 - f1223 <= 0, "Node 12 flow conservation pos"
prob += -1*(f812 + f912 + f1512 + f1712 + f2312 - f128 - f129 - f1215 - f1217 - f1223) <= 0, "Node 12 flow conservation neg"

prob += f1113 + f1413 + f1513 - f1311 - f1314 - f1315 <= 0, "Node 13 flow conservation pos"
prob += -1*(f1113 + f1413 + f1513 - f1311 - f1314 - f1315) <= 0, "Node 13 flow conservation neg"

prob += f1114 + f1314 + f1514  - f1411 - f1413 - f1415 - f1419 <= 0, "Node 14 flow conservation pos"
prob += -1*(f1114 + f1314 + f1514  - f1411 - f1413 - f1415 - f1419) <= 0, "Node 14 flow conservation neg"

prob += f1215 + f1315 + f1415 + f1615  + f2415 - f1512 - f1513 - f1514 - f1516 - f1519 - f1524 <= 0, "Node 15 flow conservation pos"
prob += -1*(f1215 + f1315 + f1415 + f1615  + f2415 - f1512 - f1513 - f1514 - f1516 - f1519 - f1524) <= 0, "Node 15 flow conservation neg"

prob += f1516 + f2416 + f2516 - f1615 - f1619 - f1624 - f1625 <= 0, "Node 16 flow conservation pos"
prob += -1*(f1516 + f2416 + f2516 - f1615 - f1619 - f1624 - f1625) <= 0, "Node 16 flow conservation neg"

prob += f1217 + f1817 + f2317 - f1712 - f1718 - f1723 <= 0, "Node 17 flow conservation pos"
prob += -1*(f1217 + f1817 + f2317 - f1712 - f1718 - f1723) <= 0, "Node 17 flow conservation neg"

prob += f618 + f718 + f1718 + f2018 + f2118 - f186 - f187 - f1817 - f1820 - f1821 <= 0, "Node 18 flow conservation pos"
prob += -1*(f618 + f718 + f1718 + f2018 + f2118 - f186 - f187 - f1817 - f1820 - f1821) <= 0, "Node 18 flow conservation neg"

##prob += f1419 + f1519 + f1619 - f1914 - f1915 - f1916 <= 0, "Node 19 flow conservation pos"
##prob += -1*(f1419 + f1519 + f1619 - f1914 - f1915 - f1916) <= 0, "Node 19 flow conservation neg"

prob += f1820 + f2220 + f2620 - f2018 - f2022 - f2026 <= 0, "Node 20 flow conservation pos"
prob += -1*(f1820 + f2220 + f2620 - f2018 - f2022 - f2026) <= 0, "Node 20 flow conservation neg"

prob += f1821 + f2221 + f2321 - f2118 - f2122 - f2123 <= 0, "Node 21 flow conservation pos"
prob += -1*(f1821 + f2221 + f2321 - f2118 - f2122 - f2123) <= 0, "Node 21 flow conservation neg"

prob += f2022 + f2122 + f2322 + f2422 + f2522 + f2622 - f2220 - f2221 - f2223 - f2224 - f2225 - f2226 <= 0, "Node 22 flow conservation pos"
prob += -1*(f2022 + f2122 + f2322 + f2422 + f2522 + f2622 - f2220 - f2221 - f2223 - f2224 - f2225 - f2226) <= 0, "Node 22 flow conservation neg"

prob += f1223 + f1723 + f2123 + f2223 + f2423 - f2312 - f2317 - f2321 - f2322 - f2324 <= 0, "Node 23 flow conservation pos"
prob += -1*(f1223 + f1723 + f2123 + f2223 + f2423 - f2312 - f2317 - f2321 - f2322 - f2324) <= 0, "Node 23 flow conservation neg"

prob += f1524 + f1624 + f2224 + f2324 - f2415 - f2416 - f2422 - f2423 <= 0, "Node 24 flow conservation pos"
prob += -1*(f1524 + f1624 + f2224 + f2324 - f2415 - f2416 - f2422 - f2423) <= 0, "Node 24 flow conservation neg"

prob += f1625 + f2225 + f2625 - f2516 - f2522 - f2526 <= 0, "Node 25 flow conservation pos"
prob += -1*(f1625 + f2225 + f2625 - f2516 - f2522 - f2526) <= 0, "Node 25 flow conservation neg"

prob += f2026 + f2226 + f2526 - f2620 - f2622 - f2625 <= 0, "Node 26 flow conservation pos"
prob += -1*(f2026 + f2226 + f2526 - f2620 - f2622 - f2625) <= 0, "Node 26 flow conservation neg"

prob.solve()

print "Status:", LpStatus[prob.status]

for variable in prob.variables():
    print variable.name, "=", variable.varValue

print "Maximum flow = ", value(prob.objective)
